package com.woniuxy.userapp.common.util;

import cn.hutool.json.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.woniuxy.commons.util.UserDto;
import com.woniuxy.commons.util.WebUtil;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * \* Created with IntelliJ IDEA.
 * \* User: Mr.zhou
 * \* Date: 2022/8/10
 * \* Time: 15:17
 * \* To change this template use File | Settings | File Templates.
 * \* Description:
 * \
 */
public class TokenToUserDtoUtil {
    public static UserDto getUserDto() throws JsonProcessingException {
        HttpServletRequest request = WebUtil.getRequest();
        String header = request.getHeader("user");
        JSONObject entries = new JSONObject(header);
        String LoginName = (String)entries.get("LoginName");
        Integer accountId = (Integer) entries.get("LoginId");
        Long LoginId = accountId.longValue() ;
        List<String> LogiRole = (List<String>)entries.get("LoginRole");
//        System.out.println(LoginName);
//        System.out.println(LoginId);
//        System.out.println(LogiRole);
        UserDto userDto = new UserDto();
        userDto.setRoles(LogiRole);
        userDto.setUserName(LoginName);
        userDto.setId(LoginId);

//        return new ObjectMapper().readValue(header,UserDto.class);
        return userDto;
    }
}
